package com.ruoyi.system.controller;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.system.domain.Shopeelistinginfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Shopeeidlistinginfo;
import com.ruoyi.system.service.IShopeeidlistinginfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * shopee印尼商品信息Controller
 * 
 * @author ruoyi
 * @date 2020-07-30
 */
@Controller
@RequestMapping("/system/shopeeidlistinginfo")
public class ShopeeidlistinginfoController extends BaseController
{
    private String prefix = "system/shopeeidlistinginfo";

    @Autowired
    private IShopeeidlistinginfoService shopeeidlistinginfoService;

    @RequiresPermissions("system:shopeeidlistinginfo:view")
    @GetMapping()
    public String shopeeidlistinginfo()
    {
        return prefix + "/shopeeidlistinginfo";
    }

    /**
     * 查询shopee印尼商品信息列表
     */
    @RequiresPermissions("system:shopeeidlistinginfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Shopeeidlistinginfo shopeeidlistinginfo)
    {
        startPage();
        List<Shopeeidlistinginfo> list = shopeeidlistinginfoService.selectShopeeidlistinginfoList(shopeeidlistinginfo);
        return getDataTable(list);
    }

    /**
     * 导出shopee印尼商品信息列表
     */
    @RequiresPermissions("system:shopeeidlistinginfo:export")
    @Log(title = "shopee印尼商品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Shopeeidlistinginfo shopeeidlistinginfo)
    {
        List<Shopeeidlistinginfo> list = shopeeidlistinginfoService.selectShopeeidlistinginfoList(shopeeidlistinginfo);
        ExcelUtil<Shopeeidlistinginfo> util = new ExcelUtil<Shopeeidlistinginfo>(Shopeeidlistinginfo.class);
        return util.exportExcel(list, "shopeeidlistinginfo");
    }

    /**
     * 新增shopee印尼商品信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存shopee印尼商品信息
     */
    @RequiresPermissions("system:shopeeidlistinginfo:add")
    @Log(title = "shopee印尼商品信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Shopeeidlistinginfo shopeeidlistinginfo)
    {
        return toAjax(shopeeidlistinginfoService.insertShopeeidlistinginfo(shopeeidlistinginfo));
    }
    /**
     * 图片展示
     */
    @GetMapping("/showimage/{itemid}")
    public String showimage(@PathVariable("itemid") String itemid, ModelMap mmap)
    {
        Shopeeidlistinginfo shopeeidlistinginfo = shopeeidlistinginfoService.selectShopeeidlistinginfoById(itemid);
        mmap.put("shopeelistinginfo", shopeeidlistinginfo);
        String[] imagesNames = shopeeidlistinginfo.getImages().replaceAll("'","").replaceAll("\\[","").replaceAll("\\]","").split(",");
        List<String> images = new ArrayList<>();
        for(String  imagename: imagesNames){
            String rooturl="https://cf.shopee.com.my/file/";
            String imageurl = rooturl+imagename.trim();
            images.add(imageurl);
        }
        mmap.put("shopeelistinginfo", shopeeidlistinginfo);
        mmap.put("images", images);
        return prefix + "/showimage";
    }
    /**
     * 修改shopee印尼商品信息
     */
    @GetMapping("/edit/{itemid}")
    public String edit(@PathVariable("itemid") String itemid, ModelMap mmap)
    {
        Shopeeidlistinginfo shopeeidlistinginfo = shopeeidlistinginfoService.selectShopeeidlistinginfoById(itemid);
        mmap.put("shopeeidlistinginfo", shopeeidlistinginfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存shopee印尼商品信息
     */
    @RequiresPermissions("system:shopeeidlistinginfo:edit")
    @Log(title = "shopee印尼商品信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Shopeeidlistinginfo shopeeidlistinginfo)
    {
        return toAjax(shopeeidlistinginfoService.updateShopeeidlistinginfo(shopeeidlistinginfo));
    }

    /**
     * 删除shopee印尼商品信息
     */
    @RequiresPermissions("system:shopeeidlistinginfo:remove")
    @Log(title = "shopee印尼商品信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(shopeeidlistinginfoService.deleteShopeeidlistinginfoByIds(ids));
    }
}
